package com.lagou.edu.controller;

import com.lagou.edu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * @Description: 用户登录接口
     * @Author: chendong
     * @Date: 2021/2/4
     **/
    @GetMapping("/login/{email}/{password}")
    public Boolean login(HttpServletRequest request, HttpServletResponse response,
                         @PathVariable String email, @PathVariable String password) throws Exception {
        return userService.login(request, response, email, password);
    }

    /**
     * @Description: 根据jwtToken获取用户邮箱
     * @Author: chendong
     * @Date: 2021/2/4
     **/
    @GetMapping("/getEmailByJwt/{jwtToken}")
    public String getEmailByJwt(@PathVariable String jwtToken) throws Exception {
        return userService.getEmailByJwt(jwtToken);
    }

    /**
     * @Description: 用户注册
     * @Author: chendong
     * @Date: 2021/2/4
     **/
    @GetMapping("/register/{email}/{password}/{code}")
    public Integer register(@PathVariable String email,@PathVariable String password,@PathVariable String code){
        return userService.register(email,password,code);
    }



}
